package svc

import (
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"navi-mumbai/app/rpc/model/pg/pay"
	pay2 "navi-mumbai/app/rpc/model/redis/pay"
	"navi-mumbai/app/rpc/pay/internal/config"
	"navi-mumbai/third/pay/epay18"
)

type ServiceContext struct {
	Config config.Config

	Epay18DepositFlowModel  pay.Epay18DepositFlowModel
	Epay18WithdrawFlowModel pay.Epay18WithdrawFlowModel

	RedisClient *redis.Redis
	PayRedis    *pay2.PayRedis
}

func NewServiceContext(c config.Config) *ServiceContext {
	sqlConn := sqlx.NewMysql(c.DB.DataSource) //sqlx.NewSqlConn(dbkey.PostgresDriverName, c.DB.DataSource)
	sc := ServiceContext{
		Config:                  c,
		Epay18WithdrawFlowModel: pay.NewEpay18WithdrawFlowModel(sqlConn, c.Cache),
		Epay18DepositFlowModel:  pay.NewEpay18DepositFlowModel(sqlConn, c.Cache),
	}

	sc.RedisClient = redis.MustNewRedis(c.Redis.RedisConf)
	sc.PayRedis = pay2.NewPayRedis(sc.RedisClient)

	epay18.InitHttpClient(c.PayChannelEPay18Conf.MerchantCode, c.PayChannelEPay18Conf.MD5Key, c.PayChannelEPay18Conf.Host, c.PayChannelEPay18Conf.NotifyUrl)
	return &sc
}
